# -*- coding: utf-8 -*-
import scrapy,json


class LoginSpider(scrapy.Spider):
    name = 'login'
    allowed_domains = ['www.renren.com']
    #start_urls = ['http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=201901222506']

    def start_requests(self):
        url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2019012325123'
        data = {
            'email': '17724265181',
            'icode':'', 
            'origURL':'http://www.renren.com/home',
            'domain':'renren.com',
            'key_id':'1',
            'captcha_type':'web_login',
            'password':'0af939692570c8e69b1add4e831d6739d4d351230fb72ef9dcf68019aac5cd8b',
            'rkey':'74040e1e85be3d7b4b2f8a655a883d22',
            'f':'http%3A%2F%2Fwww.renren.com%2F969139851',
        }
        yield scrapy.FormRequest(
                url = url,
                formdata = data,
                callback = self.parse
            )

    def parse(self, response):
        res = json.loads(response.body)
        yield scrapy.Request(url=res['homeUrl'],callback=self.parse_page)

    def parse_page(self,response):
        print(response.css("title::text").extract_first())



